import 'package:sleep/help_style.dart';
import 'package:sleep/model/blue_connection_state.dart';
import 'package:flutter/material.dart';

class ConnectItem extends StatelessWidget {
  final BlueConnectionState state;
  final String name;
  final String blueId;
  final VoidCallback ontap;
  final bool disable;
  final Widget subChild;
  final BlueType type;

  const ConnectItem(
      {Key? key,
      required this.state,
      required this.ontap,
      required this.type,
      required this.name,
      required this.blueId,
      this.disable = false,
      required this.subChild})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return disable
        ? ColorFiltered(
            colorFilter: const ColorFilter.mode(Colors.grey, BlendMode.color),
            child: child())
        : child();
  }

  Widget child() {
    bool isConnect = state == BlueConnectionState.connected;
    return GestureDetector(
      onTap: isConnect ? null : ontap,
      child: Container(
        margin: EdgeInsets.all(HelpStyle.cellMargin),
        padding: EdgeInsets.all(HelpStyle.cellMargin),
        decoration: HelpStyle.decoration,
        child: Column(
          children: [
            Row(
              children: [
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        name,
                        style: HelpStyle.titleStyle,
                      ),
                      const SizedBox(height: 4),
                      Text(
                        blueId,
                        style: HelpStyle.contextStyle,
                      ),
                    ],
                  ),
                ),
                Text(type.label, style: HelpStyle.smallStyle),
                SizedBox(width: HelpStyle.cellMargin),
                subChild,
              ],
            ),
            // BlueItemTypeWidget(onTap: (index) {}, type: BlueType.breath),
          ],
        ),
      ),
    );
  }
}
